package com.yunji.news.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunji.news.entity.AdminUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 管理员用户Mapper接口
 *
 * @author yunji
 * @since 2024-11-23
 */
@Mapper
public interface AdminUserMapper extends BaseMapper<AdminUser> {
    
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM admin_users WHERE username = #{username} AND deleted = 0")
    AdminUser selectByUsername(@Param("username") String username);
    
    /**
     * 更新最后登录信息
     */
    @Update("UPDATE admin_users SET last_login_time = NOW(), last_login_ip = #{ip} " +
            "WHERE id = #{userId}")
    void updateLastLoginInfo(@Param("userId") Long userId, @Param("ip") String ip);
}